#!/usr/bin/env bash

set -Eeuo pipefail

# TODO: maybe just use the .gitignore file to create all of these
mkdir -vp /data/sd/.cache \
  /data/sd/embeddings \
  /data/sd/config/ \
  /data/sd/models/ \
  /data/sd/models/Stable-diffusion \
  /data/sd/models/GFPGAN \
  /data/sd/models/RealESRGAN \
  /data/sd/models/LDSR \
  /data/sd/models/VAE

echo "Downloading, this might take a while..."

# Node: download the preset model, or you can replace it with another model
wget -P /data/sd/models/Stable-diffusion http://100.123.136.65:80/faas/devsapp/aigc/stable-diffusion-v1-5/models/Stable-diffusion/v1-5-pruned-emaonly.ckpt
wget -P /data/sd/models/Stable-diffusion http://100.123.136.65:80/faas/devsapp/aigc/stable-diffusion-v1-5/models/Stable-diffusion/sd-v1-5-inpainting.ckpt
wget -P /data/sd/models/VAE http://100.123.136.65:80/faas/devsapp/aigc/stable-diffusion-v1-5/models/VAE/vae-ft-mse-840000-ema-pruned.ckpt
wget -P /data/sd/models/GFPGAN http://100.123.136.65:80/faas/devsapp/aigc/stable-diffusion-v1-5/models/GFPGAN/GFPGANv1.4.pth
wget -P /data/sd/models/RealESRGAN http://100.123.136.65:80/faas/devsapp/aigc/stable-diffusion-v1-5/models/RealESRGAN/RealESRGAN_x4plus.pth
wget -P /data/sd/models/RealESRGAN http://100.123.136.65:80/faas/devsapp/aigc/stable-diffusion-v1-5/models/RealESRGAN/RealESRGAN_x4plus_anime_6B.pth
wget -P /data/sd/models/LDSR http://100.123.136.65:80/faas/devsapp/aigc/stable-diffusion-v1-5/models/LDSR/project.yaml
wget -P /data/sd/models/LDSR http://100.123.136.65:80/faas/devsapp/aigc/stable-diffusion-v1-5/models/LDSR/model.ckpt

# To be able to run stable-diffusion in a no-network environment, add openai/clip-vit-large-patch14
wget -P /data/sd http://100.123.136.65:80/faas/devsapp/aigc/stable-diffusion-v1-5/openai.zip
cd /data/sd && unzip -o openai.zip && rm -rf openai.zip

cat <<EOF
By using this software, you agree to the following licenses:
https://github.com/AbdBarho/stable-diffusion-webui-docker/blob/master/LICENSE
https://github.com/CompVis/stable-diffusion/blob/main/LICENSE
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/LICENSE.txt
https://github.com/invoke-ai/InvokeAI/blob/main/LICENSE
And licenses of all UIs, third party libraries, and extensions.
EOF
